#include"freq_selector.h"
#include"../../util.h"
FreqSelector::FreqSelector()
	:LabelSelector("FreqSelector")
{}
void FreqSelector::init(map<string, int> &query2freq)
{
	this->model = query2freq;
}
string FreqSelector::getLabel(vector<QueryNode> &group)
{
	int max_freq = 0;
	string res;
	for(int i = 0 ; i < group.size(); ++ i)
	{
		QueryNode &node = group[i];
		int freq = (*model.find(node.name)).second;
		if(freq > max_freq)
		{
			max_freq = freq;
			res = node.correction;
		}
	}
	return res;
}
string FreqSelector::getLabel(vector<string> &group)
{
	int max_freq = 0;
	string res = "";
	for(int i = 0 ; i < group.size(); ++ i)
	{
		string query = group[i];
		int freq = (*model.find(query)).second;
		if(freq > max_freq)
		{
			max_freq = freq;
			res = query;
		}
	}
	return res;
}